/*
 * Sensor acquisition tasks
 *
 * These tasks have the job of reading the sensors while everything else
 * is going on.
 *
 * by Zik Saleeba 2008-04-28
 */

#ifndef SENSOR_H
#define SENSOR_H


/* these index into the Sensor_AnalogValue array */
#if 0
enum
{
    Sensor_LevelX = 0,
    Sensor_LevelY,
    Sensor_GyroX,
    Sensor_GyroY,
    Sensor_GyroZ,
    Sensor_AccelX,
    Sensor_AccelY,
    Sensor_AccelZ
};
#endif

enum Sensor_LEDState
{
    Sensor_LEDStateNoGPS,
    Sensor_LEDStateGPSWaitLock,
    Sensor_LEDStateCalibrating,
    Sensor_LEDStateActive,
    Sensor_LEDStateManual,
    Sensor_LEDStateFatalError,
    Sensor_LEDStateMax
};

/* variables which may be read to get sensor values */
/* Note that these are all written atomically by the processor so there's
 * no need to use a mutex for consistency when accessing them */
extern volatile float   Sensor_Altitude;
extern volatile float   Sensor_Temperature;
extern volatile int     Sensor_AltitudeUpdated;

extern enum Sensor_LEDState Sensor_CurrentLEDState;

/*
 * NAME:        Sensor_StartTasks
 * ACTION:      Create the tasks which will read all the sensors and
 *              make these readings available to the rest of the system.
 * PARAMETERS:  unsigned portBASE_TYPE uxPriority - the priority to
 *                  start the tasks at
 */
void Sensor_StartTasks(unsigned portBASE_TYPE uxPriority);


/*
 * NAME:        Sensor_SetLEDState
 * ACTION:      Set the flashing style of the LEDs
 *                  NoGPS       - slow red/green
 *                  Calibrating - slow red red/green green
 *                  Active      - green flash on/off
 *                  Manual      - quick green flash, long black
 *                  FatalError  - red red red / black
 * PARAMETERS:  enum Sensor_LEDState LEDState - the state to set,
 *                  one of the options above in enum Sensor_LEDState
 */
 
static inline void Sensor_SetLEDState(enum Sensor_LEDState LEDState)
{
    Sensor_CurrentLEDState = LEDState;
}

#endif /* SENSOR_H */
